package com.yangrd.airship.generator.page.impl;

import com.yangrd.airship.generator.page.enhance.TranslateHelper;
import lombok.RequiredArgsConstructor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * description: CacheTranslateService
 *
 * @author yangrd
 * @date 2020/9/15
 */
@RequiredArgsConstructor
public class CacheTranslateHelper implements TranslateHelper {

    private final List<TranslateHelper> delegates;

    private static final Map<String, String> ENGLISH2CN_MAP = new HashMap<>();

    @Override
    public String translateCn(String english) {
        return ENGLISH2CN_MAP.computeIfAbsent(english, k -> delegates.iterator().next().translateCn(k));
    }
}
